package com.koro.controller;

import com.koro.dto.FindGoodsDTO;
import com.koro.dto.SaveGoodsDTO;
import com.koro.service.GoodsService;
import com.koro.vo.FindGoodsVO;
import com.koro.vo.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "商品管理")
@RequestMapping("/goods")
@RestController
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @ApiModelProperty(value = "更新商品",notes = "更新商品")
    @PostMapping("/save")
    public ResponseObject<Integer> save(SaveGoodsDTO dto) {
        return ResponseObject.ok(goodsService.save(dto));
    }

    @ApiModelProperty(value = "分页查询商品",notes = "分页查询")
    @PostMapping("/findAll")
    public ResponseObject<List<FindGoodsVO>> findAll(FindGoodsDTO dto) {
        return ResponseObject.ok(goodsService.findAll(dto));
    }

    @ApiModelProperty(value = "商品详情",notes = "商品详情")
    @PostMapping("/findById")
    public ResponseObject<FindGoodsVO> findById(FindGoodsDTO dto) {
        return ResponseObject.ok(goodsService.findById(dto));
    }

    @ApiOperation(value = "导入商品接口", notes = "导入商品")
    @RequestMapping(value = "importExcel", method = RequestMethod.POST)
    public ResponseObject<Integer> importExcel(@RequestParam(value = "uploadFile", required = false) MultipartFile uploadFile) throws Exception {
        return ResponseObject.ok(goodsService.importExcel(uploadFile));
    }

    @ApiOperation(value = "导出商品接口", notes = "导出商品")
    @PostMapping("/downLoad")
    public ResponseObject downLoad(HttpServletResponse response) {
        goodsService.downLoad(response);
        return ResponseObject.ok();
    }

    @ApiOperation(value = "商品同步到ES接口", notes = "商品同步到ES接口")
    @PostMapping("/synGoodsES")
    public ResponseObject synGoodsES() {
        goodsService.synGoodsES();
        return ResponseObject.ok();
    }


}
